import { queryAutoTestData, queryAutoTestRunData } from '../services/api';

export default {
  namespace: 'autotest',

  state: {
    advancedOperation1: [],
    advancedOperation2: [],
    advancedOperation3: [],
    autotest: [],
  },

  effects: {
   *fetchTestTableData(_, { call, put}) {
      const response = yield call(queryAutoTestData);
      yield put({
        type: 'show',
        payload: response,
      });
    },
    *fetchTestrunData({ payload }, { call, put }) {
      const response = yield call (queryAutoTestRunData, payload);
      yield put({
        type: 'querytestrunData',
        payload: Array.isArray(response) ? response : [],
      });
    },
  },

  reducers: {
    show(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    querytestrunData(state, action) {
      return {
        ...state,
        autotest: action.payload,
      };
    },
  },
};